#!/usr/bin/env python
# -*- coding: UTF-8 -*-

Cs = 1
Cc = 1
V = 1000
DV = 1

import math
import matplotlib as mpl
mpl.use('WxAgg')
import numpy as np
import matplotlib.pyplot as plt

Ai = np.array(xrange(1, 40))

Ds = 0.25 * Cs * Ai * Ai * Ai
Dc = 0.5 * Cc * Ai * DV/V
Dd = 0.61 * 1.22 / math.sqrt(V) / Ai

D = np.sqrt(Ds * Ds + Dc * Dc + Dd * Dd)

Dmin = 1e20
Imin = -1
for i in range(len(D)):
    d = D[i]
    if d < Dmin:
        Dmin = d
        Imin = i
print Dmin, Imin

fig = plt.figure()

ax = fig.add_subplot(111)
ax.plot(Ai, Ds, label="Ds")
ax.plot(Ai, Dc, label="Dc")
ax.plot(Ai, Dd, label="Dd")
ax.plot(Ai, D, label="D")
ax.legend()
ax.set_xlabel("Ai")
ax.set_title("for lishuai...")
plt.show()
